# -*- coding: utf-8 -*-
# @Time : 2021/9/9 19:07
# @Author : hello
# @Email : xxx@gmail.com
# @File : CRM_ST_KHGL_056.py
# @Project : crm

from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By


"""线索模块-验证查看功能"""
driver=webdriver.Chrome()
try:
    driver.implicitly_wait(30)
    driver.maximize_window()
    """前置条件-已登录crm系统且进入线索展示界面，已有线索数据"""
    cookies = {'name': 'PHPSESSID', 'value': '4f65u41tj3s8d856bn3v719pf1'}
    driver.get("http://192.168.1.155")
    driver.add_cookie(cookies)
    driver.get("http://192.168.1.155/crm/index.php?m=leads&a=add")

    lxrs = "张三"
    phones = "15632455632"

    lxr = (By.ID, 'contacts_name')
    phone = (By.ID, 'mobile')
    bc = (By.CSS_SELECTOR, 'input[value="保存"]')

    driver.find_element(*lxr).send_keys(lxrs)
    driver.find_element(*phone).send_keys(phones)
    sleep(5)
    driver.find_element(*bc).click()

    tables=(By.CSS_SELECTOR,"#form1 > table")
    tbodys=(By.TAG_NAME,"tbody")
    trs = (By.TAG_NAME, "tr")
    tds = (By.TAG_NAME, "td")
    a = (By.TAG_NAME, "a")
    table=driver.find_element(*tables)
    tbody=table.find_element(*tbodys)
    trss=tbody.find_elements(*trs)
    for tr in trss:
        td=tr.find_elements(*tds)
        if td[2]:
            td[-1].find_elements(*a)[0].click()
            break

except Exception as e:
    raise e
finally:
    sleep(3)
    driver.quit()

